package org.geek4j.base.persistence.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import lombok.Getter;
import lombok.Setter;

/**
 * @author Geek4J
 * @since 2016年4月9日 上午10:57:19
 * @description BaseEntity Common field
 */
@Getter
@Setter
@MappedSuperclass
public class BaseEntity implements Serializable {

	/**
	 * 基础实体类，用来存放公用的属性
	 */
	private static final long serialVersionUID = -1575330749646232168L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "id",length = 11, insertable=false, updatable=false)
	private Integer id;// 主键

	@Column(name = "create_date", updatable = false)
	@Temporal(TemporalType.TIMESTAMP)
	private Date createDate;// 创建时间

	@Column(name = "modify_date")
	@Temporal(TemporalType.TIMESTAMP)
	private Date modifyDate;// 更新时间

	@PrePersist
	public void addTime() {
		this.createDate = new Date();
		this.modifyDate = createDate;
	}

	@PreUpdate
	public void updateTime() {
		this.modifyDate = new Date();
	}
}
